package com.smart.business.dao;

import com.smart.entity.business.JwznEleDataEntity;
import com.smart.mybatis.dao.BaseDao;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;


/**
 * final
 *
 * @author wf
 * @since 2025-04-30 11:30:33
 */
@Mapper
public interface JwznEleDataDao extends BaseDao<JwznEleDataEntity> {
    /**
     * 获取当天指定 name 下一级的耗电百分比
     * @param name 从页面传过来的 name
     * @return 包含 name、总耗电值和百分比的 Map 列表
     */
    @MapKey("name")
    List<String> getPieChartDataByLevel(String name);


    @MapKey("name")
    List<Map<String, Integer>> getBarChartDataBy2Time(@Param("startTime") LocalDateTime startTime,
                                                      @Param("endTime") LocalDateTime endTime);




    /**
     * 获取电表的昨日当日、当周、当月消耗值
     * @param name 电表名称
     * @return 包含当日、当周、当月和当年消耗值的Map
     */
    @Select("SELECT SUM(consume) FROM jwzn_ele_data WHERE create_organization = 'COMPANY_012' AND name = #{name} AND DATE(pick_time) = CURDATE() - INTERVAL 1 DAY")
    Double getYesterConsumptionStats(@Param("name") String name);

    @Select("SELECT SUM(consume) FROM jwzn_ele_data WHERE create_organization = 'COMPANY_012' AND name = #{name} AND DATE(pick_time) = CURDATE()")
    Double getDailyConsumptionStats(@Param("name") String name);

    @Select("SELECT SUM(consume) FROM jwzn_ele_data WHERE create_organization = 'COMPANY_012' AND name = #{name} AND YEARWEEK(pick_time, 1) = YEARWEEK(CURDATE(), 1)")
    Double getWeeklyConsumptionStats(@Param("name") String name);

    @Select("SELECT SUM(consume) FROM jwzn_ele_data WHERE create_organization = 'COMPANY_012' AND name = #{name} AND DATE(pick_time) >= DATE_FORMAT(CURDATE(), '%Y-%m-01') AND DATE(pick_time) <= CURDATE()")
    Double getMonthlyConsumptionStats(@Param("name") String name);
}



